﻿$(document).ready(function () {
	kendo.culture('es-AR');
});

function getPartial(partial, where, controller) {
	$("#divContainer > div").hide();

	$.ajax({
		async: false,
		url: controller,
		data: {
			partial: partial
		},
		success: function (view) {
			$(where).html(view);
			$(where).show();
		},
		error: function (xhr, ajaxOptions, thrownError) {
			document.write(xhr.responseText);
		}
	});
}

function getUrlParameter(sParam) {
	var sPageURL = window.location.search.substring(1);
	var sURLVariables = sPageURL.split('&');

	for (var i = 0; i < sURLVariables.length; i++) {
		var sParameterName = sURLVariables[i].split('=');
		if (sParameterName[0] == sParam) {
			return sParameterName[1];
		}
	}
}

function validateForm(div) {
	var valid = true;

	$(div + " span[controlToValidate]").each(function () {
		var control = $("#" + $(this).attr('controlToValidate'));
		var validation = $(this).attr('validate').split(',');

		if (valid) {
			if ($.inArray('required', validation) != -1) {
				valid = (control.val().length != 0);
			}

			if ((valid) && ($.inArray('email', validation) != -1)) {
				debugger;

				var rg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

				valid = rg.test(control.val());
			}

			if ((valid) && ($.inArray('phone', validation) != -1)) {
				debugger;

				var rg = /^[0-9 ]{0,15}$/;

				valid = rg.test(control.val());
			}

			if ($.inArray('gridItemsCount', validation) != -1) {
				valid = (control.data("kendoGrid").dataSource.data().length > 0);
			}

			$(this).toggle(!valid);
		}
	});

	return valid;
}